package listnode;


import listnode.data.ListNode;


/**
 * 删除链表的节点
 *
 * 注意头节点
 */
public class DeleteNode {

    public ListNode deleteNode(ListNode head, int val) {

        if (head==null||head.next==null){
            return null;
        }
        ListNode pre=head;

        if (pre.val==val){
            return pre.next;
        }

        ListNode cur=head.next;

        while (cur!=null){
            if (cur.val==val){
                pre.next=cur.next;
            }
            pre=pre.next;
            cur=cur.next;
        }

        return head;
    }

    public static void main(String[] args) {
        System.out.println("Hello and welcome!");
    }
}
